package com.gemantic.task.service.support;


import java.util.List;

import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import com.gemantic.task.config.encoder.FormFeignEncoderConfig;
import com.gemantic.task.model.XxlJobGroup;
import com.gemantic.task.model.XxlJobInfo;
import com.xxl.job.core.biz.model.ReturnT;



@FeignClient(name = "XxlTaskFeignClient", url = "${xxl.job.admin.url:http://snowy-xxl-job-app:31001}", configuration = FormFeignEncoderConfig.class)
//@Conditional(JobStartCondition.class)
public interface XxlTaskFeignClient {

    @PostMapping(value = "/xxl-job-admin/jobinfo/add", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    @ResponseBody
    ReturnT<String> add(XxlJobInfo jobInfo);

    @PostMapping(value = "/xxl-job-admin/jobinfo/update", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    @ResponseBody
    ReturnT<String> update(XxlJobInfo jobInfo);

    @GetMapping("/xxl-job-admin/jobinfo/remove")
    @ResponseBody
    ReturnT<String> remove(@RequestParam Integer id);

    @GetMapping("/xxl-job-admin/jobinfo/stop")
    @ResponseBody
    ReturnT<String> stop(@RequestParam Integer id);

    @GetMapping("/xxl-job-admin/jobinfo/start")
    @ResponseBody
    ReturnT<String> start(@RequestParam Integer id);

    @GetMapping("/xxl-job-admin/jobinfo/getJob")
    @ResponseBody
    ReturnT<XxlJobInfo> getJob(@RequestParam Integer id);

    @GetMapping("/xxl-job-admin/jobinfo/nextTriggerTime")
    @ResponseBody
    ReturnT<List<String>> nextTriggerTime(@RequestParam(required = false, defaultValue = "CRON") String scheduleType, @RequestParam String scheduleConf);

    @GetMapping("/xxl-job-admin/jobgroup/loadByAppName")
    @ResponseBody
    ReturnT<XxlJobGroup> findJobGroupByAppName(@RequestParam String appName);

}
